<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <h3>演示使用跨域接口</h3>
    <button class="a">注册</button>
    <button class="b">登录</button>
    <button class="c">短信验证码</button>
    <button class="d">上传头像</button>
    <button class="e">hhhh</button>
    <script src="./dist/axios.js"></script>
    <script>

        // get 方式
        // axios.get('http://localhost:3000/user/list2')
        //     .then(
        //         response => {
        //             console.log(response.data);
        //         }
        //     )

        // // post 方式
        // axios.post('http://localhost:3000/user/detail', { user_id: '1' })
        //     .then(
        //         response => {
        //             console.log(response.data);
        //         }
        //     )


        const btn1 = document.querySelector('.a');
        const btn2 = document.querySelector('.b');
        const btn3 = document.querySelector('.c');
        const btn4 = document.querySelector('.d');
        const btn5 = document.querySelector('.e');

        btn1.onclick = () => {
            axios.post('http://127.0.0.1:3000/user/register2', { user_acc: '8888888888@qq.com' })//此处只需传账号许可
                .then(
                    response => {
                        console.log(response.data);
                    }
                )
        }
        btn2.onclick = () => {
            axios.post('http://127.0.0.1:3000/user/login2', { user_acc: '8888888888@qq.com', user_pwd: '123123', })//此处只需传账号许可
                .then(
                    response => {
                        console.log(response.data);
                    }
                )

        }

        btn5.onclick = () => {
            axios.post('http://127.0.0.1:3000/hot/hot')//此处只需传账号许可
                .then(
                    response => {
                        console.log(response.data);
                    }
                )

        }
        btn3.onclick = () => {
            axios.get('http://localhost:3000/user/send_code?email=1678454913@qq.com',)//此处只需传账号许可
                .then(
                    response => {
                        console.log(response.data);
                    }
                )
                .catch(
                    error => {
                        console.log(error);
                    }
                )
        }
        btn4.onclick = () => {
            axios.get('http://127.0.0.1:3000/user/get_avator_nickname?token=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJkYXRhIjoiODMyY2I3M2MtMDMxMy00ODg3LWJhZWMtYWIyY2JiOTI2OTQyIiwiaWF0IjoxNjgwMDczMzMyLCJleHAiOjE2ODAwODA1MzIsImlzcyI6Im9uZSJ9.4Qif1kOYZAXj-ykfhATo2UGkkq2ehADChkDpTyLHpaU',)//此处只需传账号许可
                .then(
                    response => {
                        console.log(response.data);
                    }
                )
                .catch(
                    error => {
                        console.log(error);
                    }
                )
        }
    </script>
</body>
</html>